<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单发货</title>
    <link href="../../lib/layui-v2.6.3/css/layui.css" media="all" rel="stylesheet">
    <script src="../../lib/layui-v2.6.3/layui.js"></script>
    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="../../js/template-web.js"></script>
    <style type="text/css">
        body{
            background-color: #FFFFFF;
        }
    </style>
</head>
<body>
<div>
    <div style="width: 1400px">
        <table class="layui-table" id="OrderaddressTable" lay-filter="OrderaddressTable"></table>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>物流信息补充</legend>
    </fieldset>
    <form class="layui-form layui-form-pane"  lay-filter="exampleLog">
        <div class="layui-form-item">
            <label class="layui-form-label">物流公司</label>
            <div class="layui-input-block">
                <select name="name" id="loginfoselect">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">运输单号</label>
            <div class="layui-input-inline">
                <input type="text" name="numbers" lay-verify="required" placeholder="请输入" required  autocomplete="off" class="layui-input">
            </div>
        </div>
            <button style="margin-left: 660px;margin-top: 100px" class="layui-btn layui-btn-normal" id="logsumit">提交</button>
    </form>
</div>
<script id="logtemplate" type="text/template">
    {{each datebatekind value}}
    <option value={{value.name}}>{{value.name}}</option>
    {{/each}}
</script>
<script>
    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
    var orderId = getQueryString("orderId");
    var addressId=getQueryString("address");
    var notify;
    layui.use(['notify'],function(){
        notify=layui.notify;
    })

    layui.use(['table','form','layer'], function () {
        var table = layui.table;
        var form = layui.form
        var layer = layui.layer
        var address = {
            "id": addressId
        };
        $.get("/Logistics/getList",function(ex) {
            if (ex.code==0){
                date = {datebatekind: ex.data}
                mera = template("logtemplate", date);
                $("#loginfoselect").append(mera);
                form.render('select');
            }
        })
        table.render({
            elem: '#OrderaddressTable'
            , method: 'post'
            , title: '地址信息表格'
            , url: '/address/byid' //数据接口
            , contentType: 'application/json'
            , where: address
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "data": res.data
                };
            }
            , cols: [[
                     {field: 'name', title: '收货人'}
                    , {field: 'phone', title: '收货人电话'}
                    , {field: 'region', title: '收货区域'}
                    , {field: 'address', title: '详细地址'}
                    , {field: 'phone',  title: '联系电话'}
                ]]
        });
        //表单取值
        layui.$('#logsumit').on('click', function(){
            var data = form.val('exampleLog');
            var orderUpdate={
                "lonsitics":data.name,
                "number":data.numbers,
                "id":orderId
            }
            $.ajax({
                type : "POST",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(orderUpdate),
                dataType: "json",
                url:"/order/update",
                async : true,
                success : function(date){
                    if (date.code==0) {
                        notify.success(date.msg)
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                    }else {
                        notify.error(date.msg)
                    }
                }
            })
        });
    });
</script>
</body>
</html>